/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.badlogicgames.superjumper;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class Assets {
	public static Texture background;
	public static TextureRegion backgroundRegion;
	// public static TextureRegion backgroundRegion1;

	public static Texture items;
	public static TextureRegion mainMenu;
	public static TextureRegion pauseMenu;
	public static TextureRegion ready;
	public static TextureRegion gameOver;
	public static TextureRegion highScoresRegion;
	public static TextureRegion logo;
	public static TextureRegion soundOn;
	public static TextureRegion soundOff;
	public static TextureRegion arrow;
	public static TextureRegion pause;
	public static TextureRegion spring;
	public static TextureRegion castle;
	public static TextureRegion healthBarUnit;
	public static TextureRegion staminaBarUnit;
	public static TextureRegion barBackground;
	public static TextureRegion turretNozzle;
	public static TextureRegion turretBase;
	public static Animation coinAnim;
	public static Animation bulletAnim;
	public static Animation bobJump;
	public static Animation bobFall;
	public static TextureRegion bobHit;
	public static Animation squirrelFly;
	public static TextureRegion platform;
	public static Animation brakingPlatform;
	public static BitmapFont font;

	public static Music music;
	public static Sound jumpSound;
	public static Sound highJumpSound;
	public static Sound hitSound;
	public static Sound coinSound;
	public static Sound clickSound;

	public static TextureRegion[] layers;
	public static TextureRegion gameIntro;
	public static TextureRegion adIntro;
	public static TextureRegion companyIntro;

	public static Texture loadTexture(String file) {
		return new Texture(Gdx.files.internal(file));
	}

	public static void load() {

		Texture texture = new Texture(Gdx.files.internal("data/layers.png"));
		layers = new TextureRegion[3];
		layers[0] = new TextureRegion(texture, 0, 0, 512, 352); // sky
		layers[1] = new TextureRegion(texture, 0, 363, 1024, 149); // mountains
		layers[2] = new TextureRegion(texture, 547, 0, 224, 50); // ground

		companyIntro = new TextureRegion(loadTexture("data/intro-company.png"),
				0, 0, 480, 320);
		
		adIntro = new TextureRegion(loadTexture("data/intro-ad.png"), 0, 0,
				480, 320);
		
		gameIntro = new TextureRegion(loadTexture("data/intro-game.png"), 0, 0,
				480, 320);

		background = loadTexture("data/background1.png");
		backgroundRegion = new TextureRegion(background, 0, 0, 480, 480);

		// background = loadTexture("data/background1.png");
		// backgroundRegion = new TextureRegion(background, 0, 0, 480, 480);

		items = loadTexture("data/items.png");
		mainMenu = new TextureRegion(items, 0, 224, 300, 110);
		pauseMenu = new TextureRegion(items, 224, 128, 192, 96);
		ready = new TextureRegion(items, 320, 224, 192, 32);
		gameOver = new TextureRegion(items, 352, 256, 160, 80);
		highScoresRegion = new TextureRegion(Assets.items, 0, 257, 300, 110 / 3);
		logo = new TextureRegion(items, 0, 352, 274, 142);
		soundOff = new TextureRegion(items, 0, 0, 64, 64);
		soundOn = new TextureRegion(items, 64, 0, 64, 64);
		arrow = new TextureRegion(items, 0, 64, 64, 64);
		pause = new TextureRegion(items, 64, 64, 64, 64);
		turretNozzle = new TextureRegion(items, 279, 389, 34, 79);
		turretBase = new TextureRegion(items, 312, 390, 73, 48);
		spring = new TextureRegion(items, 128, 0, 32, 32);
		castle = new TextureRegion(items, 128, 64, 64, 64);
		healthBarUnit = new TextureRegion(items, 294, 352, 204, 13);
		staminaBarUnit = new TextureRegion(items, 294, 338, 204, 13);
		barBackground = new TextureRegion(items, 294, 369, 204, 13);

		coinAnim = new Animation(0.2f,
				new TextureRegion(items, 128, 32, 32, 32), new TextureRegion(
						items, 160, 32, 32, 32), new TextureRegion(items, 192,
						32, 32, 32), new TextureRegion(items, 160, 32, 32, 32));
		bulletAnim = new Animation(0.2f, new TextureRegion(items, 128, 32, 32,
				32), new TextureRegion(items, 160, 32, 32, 32),
				new TextureRegion(items, 192, 32, 32, 32), new TextureRegion(
						items, 160, 32, 32, 32));

		bobJump = new Animation(0.2f, new TextureRegion(items, 0, 128, 32, 32),
				new TextureRegion(items, 32, 128, 32, 32));
		bobFall = new Animation(0.2f,
				new TextureRegion(items, 64, 128, 32, 32), new TextureRegion(
						items, 96, 128, 32, 32));
		bobHit = new TextureRegion(items, 128, 128, 32, 32);
		squirrelFly = new Animation(0.2f, new TextureRegion(items, 0, 160, 32,
				32), new TextureRegion(items, 32, 160, 32, 32));
		platform = new TextureRegion(items, 64, 160, 64, 16);
		brakingPlatform = new Animation(0.2f, new TextureRegion(items, 64, 160,
				64, 16), new TextureRegion(items, 64, 176, 64, 16),
				new TextureRegion(items, 64, 192, 64, 16), new TextureRegion(
						items, 64, 208, 64, 16));

		font = new BitmapFont(Gdx.files.internal("data/font.fnt"),
				Gdx.files.internal("data/font.png"), false);

		music = Gdx.audio.newMusic(Gdx.files.internal("data/music.mp3"));
		music.setLooping(true);
		music.setVolume(0.5f);
		// if(Settings.soundEnabled)
		// music.play();
		jumpSound = Gdx.audio.newSound(Gdx.files.internal("data/jump.ogg"));
		highJumpSound = Gdx.audio.newSound(Gdx.files
				.internal("data/highjump.ogg"));
		hitSound = Gdx.audio.newSound(Gdx.files.internal("data/hit.ogg"));
		coinSound = Gdx.audio.newSound(Gdx.files.internal("data/coin.ogg"));
		clickSound = Gdx.audio.newSound(Gdx.files.internal("data/click.ogg"));
	}

	public static void playSound(Sound sound) {
		if (Settings.soundEnabled)
			sound.play(1);
	}
}
